﻿using AppFramework.App.Client.ApiClient;
using AppFramework.Shared.Services.Permission;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFramework.Admin.Services.Permission
{
    public class PermissionService : IPermissionService
    {
        private readonly IApplicationContext appContext;

        public PermissionService(IApplicationContext appContext)
        {
            this.appContext = appContext;
        }

        public bool HasPermission(string key)
        {
            if (appContext.Configuration.Auth.GrantedPermissions.TryGetValue(key, out var permissionValue))
                return string.Equals(permissionValue, "true", StringComparison.OrdinalIgnoreCase);

            return false;
        }
    }
}
